<?php
Authenticate::requireUser();
try {
	$db = Db::getInstance();
	$id = Authenticate::getId();
	$query = sprintf("SELECT * FROM Invoice WHERE accountId='%s' AND DATE(dateDue)>=CURDATE() ORDER BY dateCreate DESC", $id);
	$result = $db->query($query);
	if(!$result){ throw new Exception($db->error); }
	$invoices = array();
	while($row = $result->fetch_assoc()){
		$invoices[] = $row;
	}
	
	$query = sprintf("SELECT * FROM Topic WHERE accountId='%s'", $id);
	View::display('user/index', array('invoices'=> $invoices, 'topics'=> array()));
} catch (Exception $ex) {
	Log::error($ex);
	throw $ex;
}